package com.springblog.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;

import java.time.LocalDateTime;
import java.io.Serializable;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.springframework.data.annotation.Id;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;

/**
 * <p>
 *
 * </p>
 *
 * @author ifredom@gmail.com
 * @since 2022-04-23
 */

//@EqualsAndHashCode(callSuper = false)
@TableName("m_user")
public class UserEntity implements Serializable {
    public UserEntity() {
    }

    private static final long serialVersionUID = 1L;

    @TableId(type = IdType.AUTO)
    @Id
    private Long id;

    @NotBlank(message="用户名不能为空")
    private String username;

    private String token;

    @NotEmpty(message = "avatar不能为空")
    private String avatar;

    @Email(message = "邮箱格式不合法")
    private String email;

    private String password;

    private Integer status;

    private LocalDateTime created;

    private LocalDateTime lastLogin;

    private Long roleId;

    private String deviceId;

    public UserEntity(Long id, String username, String token, String avatar, String email, String password, Integer status, LocalDateTime created, LocalDateTime lastLogin, Long roleId, String deviceId) {
        this.id = id;
        this.username = username;
        this.token = token;
        this.avatar = avatar;
        this.email = email;
        this.password = password;
        this.status = status;
        this.created = created;
        this.lastLogin = lastLogin;
        this.roleId = roleId;
        this.deviceId = deviceId;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public LocalDateTime getCreated() {
        return created;
    }

    public void setCreated(LocalDateTime created) {
        this.created = created;
    }

    public LocalDateTime getLastLogin() {
        return lastLogin;
    }

    public void setLastLogin(LocalDateTime lastLogin) {
        this.lastLogin = lastLogin;
    }

    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (o == null || getClass() != o.getClass()) return false;

        UserEntity userEntity = (UserEntity) o;

        return new EqualsBuilder().append(id, userEntity.id).append(username, userEntity.username).append(token, userEntity.token).append(avatar, userEntity.avatar).append(email, userEntity.email).append(password, userEntity.password).append(status, userEntity.status).append(created, userEntity.created).append(lastLogin, userEntity.lastLogin).append(roleId, userEntity.roleId).append(deviceId, userEntity.deviceId).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37).append(id).append(username).append(token).append(avatar).append(email).append(password).append(status).append(created).append(lastLogin).append(roleId).append(deviceId).toHashCode();
    }
}
